
package com.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnectionDB {
    /**
     * @Title:getConnection
     * @Description:TODO
     * @param @return
     * @return Connection
     * @throws
     *
     */
    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            String url = "jdbc:mysql://localhost:3306/yyzx?useUnicode=true&characterEncoding=UTF-8";

            String user = "root";

            String password = "123456";
            conn = DriverManager.getConnection(url, user, password);

        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return conn;
    }

    /**
     * @Title:closeConnection
     * @Description:TODO
     * @param @param st
     * @param @param conn
     * @return void
     * @throws
     *
     */
    public static void closeConnection(Statement st,Connection conn) {
        if(st!=null) {
            try {
                st.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }



}